package com.google.code.ojar.sendtemplatemail.app.msggenerators.imp;

import java.util.List;

import com.google.code.ojar.sendtemplatemail.app.dto.Mail;
import com.google.code.ojar.sendtemplatemail.app.exception.EmailTemplateNotFound;
import com.google.code.ojar.sendtemplatemail.app.exception.MissingConfigurationException;
import com.google.code.ojar.sendtemplatemail.app.msggenerators.MsgGenerator;

public class GenericMsgGenerator extends MsgGenerator{

	public GenericMsgGenerator() throws MissingConfigurationException {
		super();
		
	}

	@Override
	public Mail generateMailMsg(List<String> toAdds, List<String> ccAddrs,
			List<String> bccAdd, String[] args, Integer templateId)
			throws EmailTemplateNotFound, MissingConfigurationException
			 {
		
		Mail mail = new Mail(toAdds, bccAdd, ccAddrs);
		String subject = this.loadSubject(templateId);
		String msg = this.loadTemplate(templateId);
		//remplazo los tokens del template
		if(args!= null && args.length > 0){
			for(int i = 0; i < args.length; i++){
				String wordToReplace = args[i];
				msg = this.remplaceToken(msg, Integer.toString(i), wordToReplace);
			}
		}
		mail.setSubject(subject);
		mail.setMsg(msg);
		return mail;
	}

}
